package com.softcits.sp01.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.mail.EmailAttachment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MailService implements IMailService {
    private static final Logger logger = LoggerFactory.getLogger(MailService.class);
    @Autowired
    private MailHelper helper;

    @Override
    public boolean send(String... args) {
        MailInfo mailInfo = new MailInfo();
        List<String> toList = new ArrayList<String>();
        toList.add("910150090@qq.com");
        
        List<String> ccList = new ArrayList<String>();
        ccList.add("liuj_0805@163.com");
        ccList.add("910794406@qq.com");
        
        List<String> bccList = new ArrayList<String>();
        bccList.add("liuj_0805@163.com");

        EmailAttachment att = new EmailAttachment();
        att.setPath("./pom.xml");
        att.setName("Maven Configuration File");
        List<EmailAttachment> atts = new ArrayList<EmailAttachment>();
        atts.add(att);
        mailInfo.setAttachments(atts);
        
        mailInfo.setToAddress(toList);
        mailInfo.setCcAddress(ccList);
        mailInfo.setBccAddress(bccList);
        
        mailInfo.setSubject("Please review the Readme document.");
        mailInfo.setContent("<h1>Please review the Readme document.</h1>");
        helper.sendEmail(mailInfo);
        logger.debug("Finished...");
        return true;
    }

    @Override
    public boolean send(List<String> toList, List<String> ccList, List<String> bccList,
            List<EmailAttachment> atts, String subject, String cotent) {
        MailInfo mailInfo = new MailInfo();
        if(atts != null) {
            mailInfo.setAttachments(atts);
        }
        mailInfo.setToAddress(toList);
        
        if (ccList != null) {
            mailInfo.setCcAddress(ccList);
        }
        if (bccList != null) {
            mailInfo.setBccAddress(bccList);
        }
        mailInfo.setSubject(subject);
        mailInfo.setContent(cotent);
        this.helper.sendEmail(mailInfo);
        return true;
    }

    @Override
    public boolean send(List<String> toList, List<String> ccList, List<EmailAttachment> atts, String subject,
            String cotent) {
        
        return this.send(toList, ccList, null, atts, subject, cotent);
    }

    @Override
    public boolean send(List<String> toList, List<EmailAttachment> atts, String subject, String cotent) {
        return this.send(toList, null, null, atts, subject, cotent);
    }

    @Override
    public boolean send(List<String> toList, String subject, String cotent) {
        return this.send(toList, null, null, null, subject, cotent);
    }
    
    

}
